package net.ncraft.mc.ezframework.core.handler.database;

import net.ncraft.mc.ezframework.core.annotations.database.Database;

import java.lang.reflect.Proxy;

public class DatabaseCenter {

    public static <E> E getDatabase(Class<E> dataBaseClass) {

        if (!dataBaseClass.isAnnotationPresent(Database.class)) {
            return null;
        }
        Database databaseAnn = dataBaseClass.getAnnotation(Database.class);

        //noinspection unchecked
        return (E) Proxy.newProxyInstance(dataBaseClass.getClassLoader(), new Class[]{dataBaseClass},new WrapHandler(databaseAnn.value()));
    }

}

